home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / libgcc2.c < prev    next >
C/C++ Source or Header  |  1994-02-14  |  28KB  |  1,330 lines

  1. /* More subroutines needed by GCC output code on some machines.  */
  2. /* Compile this one with gcc.  */
  3. /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* As a special exception, if you link this library with files
  22.    compiled with GCC to produce an executable, this does not cause
  23.    the resulting executable to be covered by the GNU General Public License.
  24.    This exception does not however invalidate any other reasons why
  25.    the executable file might be covered by the GNU General Public License.  */
  26.  
  27. #ifndef atarist
  28.  
  29. /* It is incorrect to include config.h here, because this file is being
  30.    compiled for the target, and hence definitions concerning only the host
  31.    do not apply.  */
  32.  
  33. #include "tconfig.h"
  34. #include "machmode.h"
  35. #ifndef L_trampoline
  36. #include "gstddef.h"
  37. #endif
  38.  
  39. /* Don't use `fancy_abort' here even if config.h says to use it.  */
  40. #ifdef abort
  41. #undef abort
  42. #endif
  43.  
  44. #else
  45.  
  46. /* For the atari, include the relevant parts of config/m68k.h directly. */
  47.  
  48. #ifndef __mc68000__
  49. #define __mc68000__ 1
  50. #ifdef __M68020__
  51. #define __mc68020__ 1
  52. #endif
  53. #endif
  54.  
  55. #if __GNUC__ < 2
  56. #error This file is for GCC version 2 only.
  57. #endif
  58.  
  59. #ifndef L_trampoline
  60. #include <stddef.h>
  61. #endif
  62.  
  63. #if defined(XFLOAT_ENABLE) && (__GNUC__ > 2 || __GNUC_MINOR__ >= 4)
  64. /* Define for XFmode extended real floating point support.  */
  65. #define LONG_DOUBLE_TYPE_SIZE 96
  66. #else
  67. /* Don't try using XFmode.  */
  68. #define LONG_DOUBLE_TYPE_SIZE 64
  69. #endif
  70.  
  71. /* Define this if most significant bit is lowest numbered
  72.    in instructions that operate on numbered bit-fields.
  73.    This is true for 68020 insns such as bfins and bfexts.  */
  74. #define BITS_BIG_ENDIAN 1
  75.  
  76. /* Define this if most significant word of a multiword number is the lowest
  77.    numbered.  */
  78. /* For 68000 we can decide arbitrarily
  79.    since there are no machine instructions for them.
  80.    So let's be consistent.  */
  81. #define WORDS_BIG_ENDIAN 1
  82.  
  83. /* number of bits in an addressable storage unit */
  84. #define BITS_PER_UNIT 8
  85.  
  86. /* Width in bits of a "word", which is the contents of a machine register.
  87.    Note that this is not necessarily the width of data type `int';
  88.    if using 16-bit ints on a 68000, this would still be 32.
  89.    But on a machine with 16-bit registers, this would be 16.  */
  90. #define BITS_PER_WORD 32
  91.  
  92. /* This is the library routine that is used
  93.    to transfer control from the trampoline
  94.    to the actual nested function.  */
  95.  
  96. /* A colon is used with no explicit operands
  97.    to cause the template string to be scanned for %-constructs.  */
  98. /* The function name __transfer_from_trampoline is not actually used.
  99.    The function definition just permits use of "asm with operands"
  100.    (though the operand list is empty).  */
  101. #define TRANSFER_FROM_TRAMPOLINE                \
  102. void                                \
  103. __transfer_from_trampoline ()                    \
  104. {                                \
  105.   register char *a0 asm ("%a0");                \
  106.   asm (".globl ___trampoline");                    \
  107.   asm ("___trampoline:");                    \
  108.   asm volatile ("move%.l %0,%@" : : "m" (a0[22]));        \
  109.   asm volatile ("move%.l %1,%0" : "=a" (a0) : "m" (a0[18]));    \
  110.   asm ("rts":);                            \
  111. }
  112.  
  113. #endif /* atarist */
  114.  
  115. /* In the first part of this file, we are interfacing to calls generated
  116.    by the compiler itself.  These calls pass values into these routines
  117.    which have very specific modes (rather than very specific types), and
  118.    these compiler-generated calls also expect any return values to have
  119.    very specific modes (rather than very specific types).  Thus, we need
  120.    to avoid using regular C language type names in this part of the file
  121.    because the sizes for those types can be configured to be anything.
  122.    Instead we use the following special type names.  */
  123.  
  124. typedef unsigned int UQItype    __attribute__ ((mode (QI)));
  125. typedef      int SItype    __attribute__ ((mode (SI)));
  126. typedef unsigned int USItype    __attribute__ ((mode (SI)));
  127. typedef         int DItype    __attribute__ ((mode (DI)));
  128. typedef unsigned int UDItype    __attribute__ ((mode (DI)));
  129. typedef     float SFtype    __attribute__ ((mode (SF)));
  130. typedef        float DFtype    __attribute__ ((mode (DF)));
  131. #if LONG_DOUBLE_TYPE_SIZE == 96
  132. typedef        float XFtype    __attribute__ ((mode (XF)));
  133. #endif
  134. #if LONG_DOUBLE_TYPE_SIZE == 128
  135. typedef        float TFtype    __attribute__ ((mode (TF)));
  136. #endif
  137.  
  138. #if BITS_PER_WORD==16
  139. typedef int word_type __attribute__ ((mode (HI)));
  140. #endif
  141. #if BITS_PER_WORD==32
  142. typedef int word_type __attribute__ ((mode (SI)));
  143. #endif
  144. #if BITS_PER_WORD==64
  145. typedef int word_type __attribute__ ((mode (DI)));
  146. #endif
  147.  
  148. /* Make sure that we don't accidentally use any normal C language built-in
  149.    type names in the first part of this file.  Instead we want to use *only*
  150.    the type names defined above.  The following macro definitions insure
  151.    that if we *do* accidentally use some normal C language built-in type name,
  152.    we will get a syntax error.  */
  153.  
  154. #define char bogus_type
  155. #define short bogus_type
  156. #define int bogus_type
  157. #define long bogus_type
  158. #define unsigned bogus_type
  159. #define float bogus_type
  160. #define double bogus_type
  161.  
  162. #define SI_TYPE_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  163.  
  164. /* DIstructs are pairs of SItype values in the order determined by
  165.    WORDS_BIG_ENDIAN.  */
  166.  
  167. #if WORDS_BIG_ENDIAN
  168.   struct DIstruct {SItype high, low;};
  169. #else
  170.   struct DIstruct {SItype low, high;};
  171. #endif
  172.  
  173. /* We need this union to unpack/pack DImode values, since we don't have
  174.    any arithmetic yet.  Incoming DImode parameters are stored into the
  175.    `ll' field, and the unpacked result is read from the struct `s'.  */
  176.  
  177. typedef union
  178. {
  179.   struct DIstruct s;
  180.   DItype ll;
  181. } DIunion;
  182.  
  183. #if defined (L_udivmoddi4) || defined (L_muldi3) || defined (L_udiv_w_sdiv)
  184.  
  185. #include "longlong.h"
  186.  
  187. #endif /* udiv or mul */
  188.  
  189. extern DItype __fixunssfdi (SFtype a);
  190. extern DItype __fixunsdfdi (DFtype a);
  191. #if LONG_DOUBLE_TYPE_SIZE == 96
  192. extern DItype __fixunsxfdi (XFtype a);
  193. #endif
  194. #if LONG_DOUBLE_TYPE_SIZE == 128
  195. extern DItype __fixunstfdi (TFtype a);
  196. #endif
  197.  
  198. #if defined (L_negdi2) || defined (L_divdi3) || defined (L_moddi3)
  199. #if defined (L_divdi3) || defined (L_moddi3)
  200. static inline
  201. #endif
  202. DItype
  203. __negdi2 (u)
  204.      DItype u;
  205. {
  206.   DIunion w;
  207.   DIunion uu;
  208.  
  209.   uu.ll = u;
  210.  
  211.   w.s.low = -uu.s.low;
  212.   w.s.high = -uu.s.high - ((USItype) w.s.low > 0);
  213.  
  214.   return w.ll;
  215. }
  216. #endif
  217.  
  218. #ifdef L_lshldi3
  219. DItype
  220. __lshldi3 (u, b)
  221.      DItype u;
  222.      SItype b;
  223. {
  224.   DIunion w;
  225.   SItype bm;
  226.   DIunion uu;
  227.  
  228.   if (b == 0)
  229.     return u;
  230.  
  231.   uu.ll = u;
  232.  
  233.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  234.   if (bm <= 0)
  235.     {
  236.       w.s.low = 0;
  237.       w.s.high = (USItype)uu.s.low << -bm;
  238.     }
  239.   else
  240.     {
  241.       USItype carries = (USItype)uu.s.low >> bm;
  242.       w.s.low = (USItype)uu.s.low << b;
  243.       w.s.high = ((USItype)uu.s.high << b) | carries;
  244.     }
  245.  
  246.   return w.ll;
  247. }
  248. #endif
  249.  
  250. #ifdef L_lshrdi3
  251. DItype
  252. __lshrdi3 (u, b)
  253.      DItype u;
  254.      SItype b;
  255. {
  256.   DIunion w;
  257.   SItype bm;
  258.   DIunion uu;
  259.  
  260.   if (b == 0)
  261.     return u;
  262.  
  263.   uu.ll = u;
  264.  
  265.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  266.   if (bm <= 0)
  267.     {
  268.       w.s.high = 0;
  269.       w.s.low = (USItype)uu.s.high >> -bm;
  270.     }
  271.   else
  272.     {
  273.       USItype carries = (USItype)uu.s.high << bm;
  274.       w.s.high = (USItype)uu.s.high >> b;
  275.       w.s.low = ((USItype)uu.s.low >> b) | carries;
  276.     }
  277.  
  278.   return w.ll;
  279. }
  280. #endif
  281.  
  282. #ifdef L_ashldi3
  283. DItype
  284. __ashldi3 (u, b)
  285.      DItype u;
  286.      SItype b;
  287. {
  288.   DIunion w;
  289.   SItype bm;
  290.   DIunion uu;
  291.  
  292.   if (b == 0)
  293.     return u;
  294.  
  295.   uu.ll = u;
  296.  
  297.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  298.   if (bm <= 0)
  299.     {
  300.       w.s.low = 0;
  301.       w.s.high = (USItype)uu.s.low << -bm;
  302.     }
  303.   else
  304.     {
  305.       USItype carries = (USItype)uu.s.low >> bm;
  306.       w.s.low = (USItype)uu.s.low << b;
  307.       w.s.high = ((USItype)uu.s.high << b) | carries;
  308.     }
  309.  
  310.   return w.ll;
  311. }
  312. #endif
  313.  
  314. #ifdef L_ashrdi3
  315. DItype
  316. __ashrdi3 (u, b)
  317.      DItype u;
  318.      SItype b;
  319. {
  320.   DIunion w;
  321.   SItype bm;
  322.   DIunion uu;
  323.  
  324.   if (b == 0)
  325.     return u;
  326.  
  327.   uu.ll = u;
  328.  
  329.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  330.   if (bm <= 0)
  331.     {
  332.       /* w.s.high = 1..1 or 0..0 */
  333.       w.s.high = uu.s.high >> (sizeof (SItype) * BITS_PER_UNIT - 1);
  334.       w.s.low = uu.s.high >> -bm;
  335.     }
  336.   else
  337.     {
  338.       USItype carries = (USItype)uu.s.high << bm;
  339.       w.s.high = uu.s.high >> b;
  340.       w.s.low = ((USItype)uu.s.low >> b) | carries;
  341.     }
  342.  
  343.   return w.ll;
  344. }
  345. #endif
  346.  
  347. #ifdef L_ffsdi2
  348. DItype
  349. __ffsdi2 (u)
  350.      DItype u;
  351. {
  352.   DIunion uu, w;
  353.   uu.ll = u;
  354.   w.s.high = 0;
  355.   w.s.low = ffs (uu.s.low);
  356.   if (w.s.low != 0)
  357.     return w.ll;
  358.   w.s.low = ffs (uu.s.high);
  359.   if (w.s.low != 0)
  360.     {
  361.       w.s.low += BITS_PER_UNIT * sizeof (SItype);
  362.       return w.ll;
  363.     }
  364.   return w.ll;
  365. }
  366. #endif
  367.  
  368. #ifdef L_muldi3
  369. DItype
  370. __muldi3 (u, v)
  371.      DItype u, v;
  372. {
  373.   DIunion w;
  374.   DIunion uu, vv;
  375.  
  376.   uu.ll = u,
  377.   vv.ll = v;
  378.  
  379.   w.ll = __umulsidi3 (uu.s.low, vv.s.low);
  380.   w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
  381.            + (USItype) uu.s.high * (USItype) vv.s.low);
  382.  
  383.   return w.ll;
  384. }
  385. #endif
  386.  
  387. #ifdef L_udiv_w_sdiv
  388. USItype
  389. __udiv_w_sdiv (rp, a1, a0, d)
  390.      USItype *rp, a1, a0, d;
  391. {
  392.   USItype q, r;
  393.   USItype c0, c1, b1;
  394.  
  395.   if ((SItype) d >= 0)
  396.     {
  397.       if (a1 < d - a1 - (a0 >> (SI_TYPE_SIZE - 1)))
  398.     {
  399.       /* dividend, divisor, and quotient are nonnegative */
  400.       sdiv_qrnnd (q, r, a1, a0, d);
  401.     }
  402.       else
  403.     {
  404.       /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
  405.       sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (SI_TYPE_SIZE - 1));
  406.       /* Divide (c1*2^32 + c0) by d */
  407.       sdiv_qrnnd (q, r, c1, c0, d);
  408.       /* Add 2^31 to quotient */
  409.       q += (USItype) 1 << (SI_TYPE_SIZE - 1);
  410.     }
  411.     }
  412.   else
  413.     {
  414.       b1 = d >> 1;            /* d/2, between 2^30 and 2^31 - 1 */
  415.       c1 = a1 >> 1;            /* A/2 */
  416.       c0 = (a1 << (SI_TYPE_SIZE - 1)) + (a0 >> 1);
  417.  
  418.       if (a1 < b1)            /* A < 2^32*b1, so A/2 < 2^31*b1 */
  419.     {
  420.       sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
  421.  
  422.       r = 2*r + (a0 & 1);        /* Remainder from A/(2*b1) */
  423.       if ((d & 1) != 0)
  424.         {
  425.           if (r >= q)
  426.         r = r - q;
  427.           else if (q - r <= d)
  428.         {
  429.           r = r - q + d;
  430.           q--;
  431.         }
  432.           else
  433.         {
  434.           r = r - q + 2*d;
  435.           q -= 2;
  436.         }
  437.         }
  438.     }
  439.       else if (c1 < b1)            /* So 2^31 <= (A/2)/b1 < 2^32 */
  440.     {
  441.       c1 = (b1 - 1) - c1;
  442.       c0 = ~c0;            /* logical NOT */
  443.  
  444.       sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
  445.  
  446.       q = ~q;            /* (A/2)/b1 */
  447.       r = (b1 - 1) - r;
  448.  
  449.       r = 2*r + (a0 & 1);        /* A/(2*b1) */
  450.  
  451.       if ((d & 1) != 0)
  452.         {
  453.           if (r >= q)
  454.         r = r - q;
  455.           else if (q - r <= d)
  456.         {
  457.           r = r - q + d;
  458.           q--;
  459.         }
  460.           else
  461.         {
  462.           r = r - q + 2*d;
  463.           q -= 2;
  464.         }
  465.         }
  466.     }
  467.       else                /* Implies c1 = b1 */
  468.     {                /* Hence a1 = d - 1 = 2*b1 - 1 */
  469.       if (a0 >= -d)
  470.         {
  471.           q = -1;
  472.           r = a0 + d;
  473.         }
  474.       else
  475.         {
  476.           q = -2;
  477.           r = a0 + 2*d;
  478.         }
  479.     }
  480.     }
  481.  
  482.   *rp = r;
  483.   return q;
  484. }
  485. #endif
  486.  
  487. #ifdef L_udivmoddi4
  488. static const UQItype __clz_tab[] =
  489. {
  490.   0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
  491.   6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  492.   7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
  493.   7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
  494.   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
  495.   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
  496.   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
  497.   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
  498. };
  499.  
  500. UDItype
  501. __udivmoddi4 (n, d, rp)
  502.      UDItype n, d;
  503.      UDItype *rp;
  504. {
  505.   DIunion ww;
  506.   DIunion nn, dd;
  507.   DIunion rr;
  508.   USItype d0, d1, n0, n1, n2;
  509.   USItype q0, q1;
  510.   USItype b, bm;
  511.  
  512.   nn.ll = n;
  513.   dd.ll = d;
  514.  
  515.   d0 = dd.s.low;
  516.   d1 = dd.s.high;
  517.   n0 = nn.s.low;
  518.   n1 = nn.s.high;
  519.  
  520. #if !UDIV_NEEDS_NORMALIZATION
  521.   if (d1 == 0)
  522.     {
  523.       if (d0 > n1)
  524.     {
  525.       /* 0q = nn / 0D */
  526.  
  527.       udiv_qrnnd (q0, n0, n1, n0, d0);
  528.       q1 = 0;
  529.  
  530.       /* Remainder in n0.  */
  531.     }
  532.       else
  533.     {
  534.       /* qq = NN / 0d */
  535.  
  536.       if (d0 == 0)
  537.         d0 = 1 / d0;    /* Divide intentionally by zero.  */
  538.  
  539.       udiv_qrnnd (q1, n1, 0, n1, d0);
  540.       udiv_qrnnd (q0, n0, n1, n0, d0);
  541.  
  542.       /* Remainder in n0.  */
  543.     }
  544.  
  545.       if (rp != 0)
  546.     {
  547.       rr.s.low = n0;
  548.       rr.s.high = 0;
  549.       *rp = rr.ll;
  550.     }
  551.     }
  552.  
  553. #else /* UDIV_NEEDS_NORMALIZATION */
  554.  
  555.   if (d1 == 0)
  556.     {
  557.       if (d0 > n1)
  558.     {
  559.       /* 0q = nn / 0D */
  560.  
  561.       count_leading_zeros (bm, d0);
  562.  
  563.       if (bm != 0)
  564.         {
  565.           /* Normalize, i.e. make the most significant bit of the
  566.          denominator set.  */
  567.  
  568.           d0 = d0 << bm;
  569.           n1 = (n1 << bm) | (n0 >> (SI_TYPE_SIZE - bm));
  570.           n0 = n0 << bm;
  571.         }
  572.  
  573.       udiv_qrnnd (q0, n0, n1, n0, d0);
  574.       q1 = 0;
  575.  
  576.       /* Remainder in n0 >> bm.  */
  577.     }
  578.       else
  579.     {
  580.       /* qq = NN / 0d */
  581.  
  582.       if (d0 == 0)
  583.         d0 = 1 / d0;    /* Divide intentionally by zero.  */
  584.  
  585.       count_leading_zeros (bm, d0);
  586.  
  587.       if (bm == 0)
  588.         {
  589.           /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
  590.          conclude (the most significant bit of n1 is set) /\ (the
  591.          leading quotient digit q1 = 1).
  592.  
  593.          This special case is necessary, not an optimization.
  594.          (Shifts counts of SI_TYPE_SIZE are undefined.)  */
  595.  
  596.           n1 -= d0;
  597.           q1 = 1;
  598.         }
  599.       else
  600.         {
  601.           /* Normalize.  */
  602.  
  603.           b = SI_TYPE_SIZE - bm;
  604.  
  605.           d0 = d0 << bm;
  606.           n2 = n1 >> b;
  607.           n1 = (n1 << bm) | (n0 >> b);
  608.           n0 = n0 << bm;
  609.  
  610.           udiv_qrnnd (q1, n1, n2, n1, d0);
  611.         }
  612.  
  613.       /* n1 != d0... */
  614.  
  615.       udiv_qrnnd (q0, n0, n1, n0, d0);
  616.  
  617.       /* Remainder in n0 >> bm.  */
  618.     }
  619.  
  620.       if (rp != 0)
  621.     {
  622.       rr.s.low = n0 >> bm;
  623.       rr.s.high = 0;
  624.       *rp = rr.ll;
  625.     }
  626.     }
  627. #endif /* UDIV_NEEDS_NORMALIZATION */
  628.  
  629.   else
  630.     {
  631.       if (d1 > n1)
  632.     {
  633.       /* 00 = nn / DD */
  634.  
  635.       q0 = 0;
  636.       q1 = 0;
  637.  
  638.       /* Remainder in n1n0.  */
  639.       if (rp != 0)
  640.         {
  641.           rr.s.low = n0;
  642.           rr.s.high = n1;
  643.           *rp = rr.ll;
  644.         }
  645.     }
  646.       else
  647.     {
  648.       /* 0q = NN / dd */
  649.  
  650.       count_leading_zeros (bm, d1);
  651.       if (bm == 0)
  652.         {
  653.           /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
  654.          conclude (the most significant bit of n1 is set) /\ (the
  655.          quotient digit q0 = 0 or 1).
  656.  
  657.          This special case is necessary, not an optimization.  */
  658.  
  659.           /* The condition on the next line takes advantage of that
  660.          n1 >= d1 (true due to program flow).  */
  661.           if (n1 > d1 || n0 >= d0)
  662.         {
  663.           q0 = 1;
  664.           sub_ddmmss (n1, n0, n1, n0, d1, d0);
  665.         }
  666.           else
  667.         q0 = 0;
  668.  
  669.           q1 = 0;
  670.  
  671.           if (rp != 0)
  672.         {
  673.           rr.s.low = n0;
  674.           rr.s.high = n1;
  675.           *rp = rr.ll;
  676.         }
  677.         }
  678.       else
  679.         {
  680.           USItype m1, m0;
  681.           /* Normalize.  */
  682.  
  683.           b = SI_TYPE_SIZE - bm;
  684.  
  685.           d1 = (d1 << bm) | (d0 >> b);
  686.           d0 = d0 << bm;
  687.           n2 = n1 >> b;
  688.           n1 = (n1 << bm) | (n0 >> b);
  689.           n0 = n0 << bm;
  690.  
  691.           udiv_qrnnd (q0, n1, n2, n1, d1);
  692.           umul_ppmm (m1, m0, q0, d0);
  693.  
  694.           if (m1 > n1 || (m1 == n1 && m0 > n0))
  695.         {
  696.           q0--;
  697.           sub_ddmmss (m1, m0, m1, m0, d1, d0);
  698.         }
  699.  
  700.           q1 = 0;
  701.  
  702.           /* Remainder in (n1n0 - m1m0) >> bm.  */
  703.           if (rp != 0)
  704.         {
  705.           sub_ddmmss (n1, n0, n1, n0, m1, m0);
  706.           rr.s.low = (n1 << b) | (n0 >> bm);
  707.           rr.s.high = n1 >> bm;
  708.           *rp = rr.ll;
  709.         }
  710.         }
  711.     }
  712.     }
  713.  
  714.   ww.s.low = q0;
  715.   ww.s.high = q1;
  716.   return ww.ll;
  717. }
  718. #endif
  719.  
  720. #ifdef L_divdi3
  721. UDItype __udivmoddi4 ();
  722.  
  723. DItype
  724. __divdi3 (u, v)
  725.      DItype u, v;
  726. {
  727.   SItype c = 0;
  728.   DIunion uu, vv;
  729.   DItype w;
  730.  
  731.   uu.ll = u;
  732.   vv.ll = v;
  733.  
  734.   if (uu.s.high < 0)
  735.     c = ~c,
  736.     uu.ll = __negdi2 (uu.ll);
  737.   if (vv.s.high < 0)
  738.     c = ~c,
  739.     vv.ll = __negdi2 (vv.ll);
  740.  
  741.   w = __udivmoddi4 (uu.ll, vv.ll, (UDItype *) 0);
  742.   if (c)
  743.     w = __negdi2 (w);
  744.  
  745.   return w;
  746. }
  747. #endif
  748.  
  749. #ifdef L_moddi3
  750. UDItype __udivmoddi4 ();
  751. DItype
  752. __moddi3 (u, v)
  753.      DItype u, v;
  754. {
  755.   SItype c = 0;
  756.   DIunion uu, vv;
  757.   DItype w;
  758.  
  759.   uu.ll = u;
  760.   vv.ll = v;
  761.  
  762.   if (uu.s.high < 0)
  763.     c = ~c,
  764.     uu.ll = __negdi2 (uu.ll);
  765.   if (vv.s.high < 0)
  766.     vv.ll = __negdi2 (vv.ll);
  767.  
  768.   (void) __udivmoddi4 (uu.ll, vv.ll, &w);
  769.   if (c)
  770.     w = __negdi2 (w);
  771.  
  772.   return w;
  773. }
  774. #endif
  775.  
  776. #ifdef L_umoddi3
  777. UDItype __udivmoddi4 ();
  778. UDItype
  779. __umoddi3 (u, v)
  780.      UDItype u, v;
  781. {
  782.   DItype w;
  783.  
  784.   (void) __udivmoddi4 (u, v, &w);
  785.  
  786.   return w;
  787. }
  788. #endif
  789.  
  790. #ifdef L_udivdi3
  791. UDItype __udivmoddi4 ();
  792. UDItype
  793. __udivdi3 (n, d)
  794.      UDItype n, d;
  795. {
  796.   return __udivmoddi4 (n, d, (UDItype *) 0);
  797. }
  798. #endif
  799.  
  800. #ifdef L_cmpdi2
  801. word_type
  802. __cmpdi2 (a, b)
  803.      DItype a, b;
  804. {
  805.   DIunion au, bu;
  806.  
  807.   au.ll = a, bu.ll = b;
  808.  
  809.   if (au.s.high < bu.s.high)
  810.     return 0;
  811.   else if (au.s.high > bu.s.high)
  812.     return 2;
  813.   if ((USItype) au.s.low < (USItype) bu.s.low)
  814.     return 0;
  815.   else if ((USItype) au.s.low > (USItype) bu.s.low)
  816.     return 2;
  817.   return 1;
  818. }
  819. #endif
  820.  
  821. #ifdef L_ucmpdi2
  822. word_type
  823. __ucmpdi2 (a, b)
  824.      DItype a, b;
  825. {
  826.   DIunion au, bu;
  827.  
  828.   au.ll = a, bu.ll = b;
  829.  
  830.   if ((USItype) au.s.high < (USItype) bu.s.high)
  831.     return 0;
  832.   else if ((USItype) au.s.high > (USItype) bu.s.high)
  833.     return 2;
  834.   if ((USItype) au.s.low < (USItype) bu.s.low)
  835.     return 0;
  836.   else if ((USItype) au.s.low > (USItype) bu.s.low)
  837.     return 2;
  838.   return 1;
  839. }
  840. #endif
  841.  
  842. #if defined(L_fixunstfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
  843. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  844. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  845.  
  846. DItype
  847. __fixunstfdi (a)
  848.      TFtype a;
  849. {
  850.   TFtype b;
  851.   UDItype v;
  852.  
  853.   if (a < 0)
  854.     return 0;
  855.  
  856.   /* Compute high word of result, as a flonum.  */
  857.   b = (a / HIGH_WORD_COEFF);
  858.   /* Convert that to fixed (but not to DItype!),
  859.      and shift it into the high word.  */
  860.   v = (USItype) b;
  861.   v <<= WORD_SIZE;
  862.   /* Remove high part from the TFtype, leaving the low part as flonum.  */
  863.   a -= (TFtype)v;
  864.   /* Convert that to fixed (but not to DItype!) and add it in.
  865.      Sometimes A comes out negative.  This is significant, since
  866.      A has more bits than a long int does.  */
  867.   if (a < 0)
  868.     v -= (USItype) (- a);
  869.   else
  870.     v += (USItype) a;
  871.   return v;
  872. }
  873. #endif
  874.  
  875. #if defined(L_fixtfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
  876. DItype
  877. __fixtfdi (a)
  878.      TFtype a;
  879. {
  880.   if (a < 0)
  881.     return - __fixunstfdi (-a);
  882.   return __fixunstfdi (a);
  883. }
  884. #endif
  885.  
  886. #if defined(L_fixunsxfdi) && (LONG_DOUBLE_TYPE_SIZE == 96)
  887. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  888. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  889.  
  890. DItype
  891. __fixunsxfdi (a)
  892.      XFtype a;
  893. {
  894.   XFtype b;
  895.   UDItype v;
  896.  
  897.   if (a < 0)
  898.     return 0;
  899.  
  900.   /* Compute high word of result, as a flonum.  */
  901.   b = (a / HIGH_WORD_COEFF);
  902.   /* Convert that to fixed (but not to DItype!),
  903.      and shift it into the high word.  */
  904.   v = (USItype) b;
  905.   v <<= WORD_SIZE;
  906.   /* Remove high part from the XFtype, leaving the low part as flonum.  */
  907.   a -= (XFtype)v;
  908.   /* Convert that to fixed (but not to DItype!) and add it in.
  909.      Sometimes A comes out negative.  This is significant, since
  910.      A has more bits than a long int does.  */
  911.   if (a < 0)
  912.     v -= (USItype) (- a);
  913.   else
  914.     v += (USItype) a;
  915.   return v;
  916. }
  917. #endif
  918.  
  919. #if defined(L_fixxfdi) && (LONG_DOUBLE_TYPE_SIZE == 96)
  920. DItype
  921. __fixxfdi (a)
  922.      XFtype a;
  923. {
  924.   if (a < 0)
  925.     return - __fixunsxfdi (-a);
  926.   return __fixunsxfdi (a);
  927. }
  928. #endif
  929.  
  930. #ifdef L_fixunsdfdi
  931. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  932. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  933.  
  934. DItype
  935. __fixunsdfdi (a)
  936.      DFtype a;
  937. {
  938.   DFtype b;
  939.   UDItype v;
  940.  
  941.   if (a < 0)
  942.     return 0;
  943.  
  944.   /* Compute high word of result, as a flonum.  */
  945.   b = (a / HIGH_WORD_COEFF);
  946.   /* Convert that to fixed (but not to DItype!),
  947.      and shift it into the high word.  */
  948.   v = (USItype) b;
  949.   v <<= WORD_SIZE;
  950.   /* Remove high part from the DFtype, leaving the low part as flonum.  */
  951.   a -= (DFtype)v;
  952.   /* Convert that to fixed (but not to DItype!) and add it in.
  953.      Sometimes A comes out negative.  This is significant, since
  954.      A has more bits than a long int does.  */
  955.   if (a < 0)
  956.     v -= (USItype) (- a);
  957.   else
  958.     v += (USItype) a;
  959.   return v;
  960. }
  961. #endif
  962.  
  963. #ifdef L_fixdfdi
  964. DItype
  965. __fixdfdi (a)
  966.      DFtype a;
  967. {
  968.   if (a < 0)
  969.     return - __fixunsdfdi (-a);
  970.   return __fixunsdfdi (a);
  971. }
  972. #endif
  973.  
  974. #ifdef L_fixunssfdi
  975. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  976. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  977.  
  978. DItype
  979. __fixunssfdi (SFtype original_a)
  980. {
  981.   /* Convert the SFtype to a DFtype, because that is surely not going
  982.      to lose any bits.  Some day someone else can write a faster version
  983.      that avoids converting to DFtype, and verify it really works right.  */
  984.   DFtype a = original_a;
  985.   DFtype b;
  986.   UDItype v;
  987.  
  988.   if (a < 0)
  989.     return 0;
  990.  
  991.   /* Compute high word of result, as a flonum.  */
  992.   b = (a / HIGH_WORD_COEFF);
  993.   /* Convert that to fixed (but not to DItype!),
  994.      and shift it into the high word.  */
  995.   v = (USItype) b;
  996.   v <<= WORD_SIZE;
  997.   /* Remove high part from the DFtype, leaving the low part as flonum.  */
  998.   a -= (DFtype)v;
  999.   /* Convert that to fixed (but not to DItype!) and add it in.
  1000.      Sometimes A comes out negative.  This is significant, since
  1001.      A has more bits than a long int does.  */
  1002.   if (a < 0)
  1003.     v -= (USItype) (- a);
  1004.   else
  1005.     v += (USItype) a;
  1006.   return v;
  1007. }
  1008. #endif
  1009.  
  1010. #ifdef L_fixsfdi
  1011. DItype
  1012. __fixsfdi (SFtype a)
  1013. {
  1014.   if (a < 0)
  1015.     return - __fixunssfdi (-a);
  1016.   return __fixunssfdi (a);
  1017. }
  1018. #endif
  1019.  
  1020. #if defined(L_floatdixf) && (LONG_DOUBLE_TYPE_SIZE == 96)
  1021. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  1022. #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
  1023. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  1024.  
  1025. XFtype
  1026. __floatdixf (u)
  1027.      DItype u;
  1028. {
  1029.   XFtype d;
  1030.   SItype negate = 0;
  1031.  
  1032.   if (u < 0)
  1033.     u = -u, negate = 1;
  1034.  
  1035.   d = (USItype) (u >> WORD_SIZE);
  1036.   d *= HIGH_HALFWORD_COEFF;
  1037.   d *= HIGH_HALFWORD_COEFF;
  1038.   d += (USItype) (u & (HIGH_WORD_COEFF - 1));
  1039.  
  1040.   return (negate ? -d : d);
  1041. }
  1042. #endif
  1043.  
  1044. #if defined(L_floatditf) && (LONG_DOUBLE_TYPE_SIZE == 128)
  1045. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  1046. #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
  1047. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  1048.  
  1049. TFtype
  1050. __floatditf (u)
  1051.      DItype u;
  1052. {
  1053.   TFtype d;
  1054.   SItype negate = 0;
  1055.  
  1056.   if (u < 0)
  1057.     u = -u, negate = 1;
  1058.  
  1059.   d = (USItype) (u >> WORD_SIZE);
  1060.   d *= HIGH_HALFWORD_COEFF;
  1061.   d *= HIGH_HALFWORD_COEFF;
  1062.   d += (USItype) (u & (HIGH_WORD_COEFF - 1));
  1063.  
  1064.   return (negate ? -d : d);
  1065. }
  1066. #endif
  1067.  
  1068. #ifdef L_floatdidf
  1069. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  1070. #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
  1071. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  1072.  
  1073. DFtype
  1074. __floatdidf (u)
  1075.      DItype u;
  1076. {
  1077.   DFtype d;
  1078.   SItype negate = 0;
  1079.  
  1080.   if (u < 0)
  1081.     u = -u, negate = 1;
  1082.  
  1083.   d = (USItype) (u >> WORD_SIZE);
  1084.   d *= HIGH_HALFWORD_COEFF;
  1085.   d *= HIGH_HALFWORD_COEFF;
  1086.   d += (USItype) (u & (HIGH_WORD_COEFF - 1));
  1087.  
  1088.   return (negate ? -d : d);
  1089. }
  1090. #endif
  1091.  
  1092. #ifdef L_floatdisf
  1093. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  1094. #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
  1095. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  1096.  
  1097. SFtype
  1098. __floatdisf (u)
  1099.      DItype u;
  1100. {
  1101.   /* Do the calculation in DFmode
  1102.      so that we don't lose any of the precision of the high word
  1103.      while multiplying it.  */
  1104.   DFtype f;
  1105.   SItype negate = 0;
  1106.  
  1107.   if (u < 0)
  1108.     u = -u, negate = 1;
  1109.  
  1110.   f = (USItype) (u >> WORD_SIZE);
  1111.   f *= HIGH_HALFWORD_COEFF;
  1112.   f *= HIGH_HALFWORD_COEFF;
  1113.   f += (USItype) (u & (HIGH_WORD_COEFF - 1));
  1114.  
  1115.   return (SFtype) (negate ? -f : f);
  1116. }
  1117. #endif
  1118.  
  1119. #if defined(L_fixunsxfsi) && LONG_DOUBLE_TYPE_SIZE == 96
  1120. #include <limits.h>
  1121.  
  1122. USItype
  1123. __fixunsxfsi (a)
  1124.      XFtype a;
  1125. {
  1126.   if (a >= - (DFtype) LONG_MIN)
  1127.     return (SItype) (a + LONG_MIN) - LONG_MIN;
  1128.   return (SItype) a;
  1129. }
  1130. #endif
  1131.  
  1132. #ifdef L_fixunsdfsi
  1133. #include <limits.h>
  1134.  
  1135. USItype
  1136. __fixunsdfsi (a)
  1137.      DFtype a;
  1138. {
  1139.   if (a >= - (DFtype) LONG_MIN)
  1140.     return (SItype) (a + LONG_MIN) - LONG_MIN;
  1141.   return (SItype) a;
  1142. }
  1143. #endif
  1144.  
  1145. #ifdef L_fixunssfsi
  1146. #include <limits.h>
  1147.  
  1148. USItype
  1149. __fixunssfsi (SFtype a)
  1150. {
  1151.   if (a >= - (SFtype) LONG_MIN)
  1152.     return (SItype) (a + LONG_MIN) - LONG_MIN;
  1153.   return (SItype) a;
  1154. }
  1155. #endif
  1156.  
  1157. /* From here on down, the routines use normal data types.  */
  1158.  
  1159. #define SItype bogus_type
  1160. #define USItype bogus_type
  1161. #define DItype bogus_type
  1162. #define UDItype bogus_type
  1163. #define SFtype bogus_type
  1164. #define DFtype bogus_type
  1165.  
  1166. #undef char
  1167. #undef short
  1168. #undef int
  1169. #undef long
  1170. #undef unsigned
  1171. #undef float
  1172. #undef double
  1173.  
  1174. /* frills for C++ */
  1175.  
  1176. #ifdef L_op_new
  1177. #include <memory.h>
  1178.  
  1179. typedef void (*vfp)(void);
  1180.  
  1181. extern vfp __new_handler;
  1182.  
  1183. /* void * operator new (size_t sz) */
  1184. void *
  1185. __builtin_new (size_t sz)
  1186. {
  1187.   void *p;
  1188.  
  1189.   /* malloc (0) is unpredictable; avoid it.  */
  1190.   if (sz == 0)
  1191.     sz = 1;
  1192.   p = (void *) malloc (sz);
  1193.   if (p == 0)
  1194.     (*__new_handler) ();
  1195.   return p;
  1196. }
  1197. #endif /* L_op_new */
  1198.  
  1199. #ifdef L_new_handler
  1200.  
  1201.   /* Avoid forcing the library's meaning of `write' on the user program
  1202.      by using the "internal" name (for use within the library)  */
  1203. #define write(fd, buf, n)    _write((fd), (buf), (n))
  1204.  
  1205. typedef void (*vfp)(void);
  1206.  
  1207. extern void *__builtin_new (size_t);
  1208. static void default_new_handler (void);
  1209.  
  1210. vfp __new_handler = default_new_handler;
  1211.  
  1212. vfp
  1213. __set_new_handler (handler)
  1214.      vfp handler;
  1215. {
  1216.   vfp prev_handler;
  1217.  
  1218.   prev_handler = __new_handler;
  1219.   if (handler == 0) handler = default_new_handler;
  1220.   __new_handler = handler;
  1221.   return prev_handler;
  1222. }
  1223.  
  1224. vfp
  1225. set_new_handler (handler)
  1226.      vfp handler;
  1227. {
  1228.   return __set_new_handler (handler);
  1229. }
  1230.  
  1231. #define MESSAGE "Virtual memory exceeded in `new'\n"
  1232.  
  1233. static void
  1234. default_new_handler ()
  1235. {
  1236.   /* don't use fprintf (stderr, ...) because it may need to call malloc.  */
  1237.   /* This should really print the name of the program, but that is hard to
  1238.      do.  We need a standard, clean way to get at the name.  */
  1239.   write (2, MESSAGE, sizeof (MESSAGE));
  1240.   /* don't call exit () because that may call global destructors which
  1241.      may cause a loop.  */
  1242.   _exit (-1);
  1243. }
  1244. #endif
  1245.  
  1246. #ifdef L_op_delete
  1247. /* void operator delete (void *ptr) */
  1248. void
  1249. __builtin_delete (void *ptr)
  1250. {
  1251.   if (ptr)
  1252.     free (ptr);
  1253. }
  1254. #endif
  1255.  
  1256. #ifdef L_trampoline
  1257.  
  1258. /* Jump to a trampoline, loading the static chain address.  */
  1259.  
  1260. #ifdef TRANSFER_FROM_TRAMPOLINE 
  1261. TRANSFER_FROM_TRAMPOLINE 
  1262. #endif
  1263. #endif /* L_trampoline */
  1264.  
  1265. #ifdef L__main
  1266.  
  1267. #include "gbl-ctors.h"
  1268.  
  1269. /* Run all the global destructors on exit from the program.  */
  1270.  
  1271. void
  1272. __do_global_dtors ()
  1273. {
  1274.   unsigned nptrs = (unsigned long) __DTOR_LIST__[0];
  1275.   unsigned i;
  1276.  
  1277.   /* Some systems place the number of pointers
  1278.      in the first word of the table.
  1279.      On other systems, that word is -1.
  1280.      In all cases, the table is null-terminated.  */
  1281.  
  1282.   /* If the length is not recorded, count up to the null.  */
  1283.   if (nptrs == -1)
  1284.     for (nptrs = 0; __DTOR_LIST__[nptrs + 1] != 0; nptrs++);
  1285.  
  1286.   /* GNU LD format.  */
  1287.   for (i = nptrs; i >= 1; i--)
  1288.     __DTOR_LIST__[i] ();
  1289. }
  1290.  
  1291. /* Run all the global constructors on entry to the program.  */
  1292.  
  1293. void
  1294. __do_global_ctors ()
  1295. {
  1296.   DO_GLOBAL_CTORS_BODY;
  1297. }
  1298.  
  1299. /* Subroutine called automatically by `main'.
  1300.    Compiling a global function named `main'
  1301.    produces an automatic call to this function at the beginning.
  1302.  
  1303.    For many systems, this routine calls __do_global_ctors.
  1304.    For systems which support a .init section we use the .init section
  1305.    to run __do_global_ctors, so we need not do anything here.  */
  1306.  
  1307. void
  1308. __main ()
  1309. {
  1310.   /* Support recursive calls to `main': run initializers just once.  */
  1311.   static int initialized = 0;
  1312.   if (! initialized)
  1313.     {
  1314.       initialized = 1;
  1315.       __do_global_ctors ();
  1316.     }
  1317. }
  1318.  
  1319. #endif /* L__main */
  1320.  
  1321. #ifdef L_ctor_list
  1322. #include "gbl-ctors.h"
  1323. const func_ptr __CTOR_LIST__[2] = {0, 0};
  1324. #endif /* L_ctor_list */
  1325.  
  1326. #ifdef L_dtor_list
  1327. #include "gbl-ctors.h"
  1328. const func_ptr __DTOR_LIST__[2] = {0, 0};
  1329. #endif /* L_ctor_list */
  1330.